package com.thinkingstar.iads.datacenter.entity.dao;

import java.util.List;

import javax.jcr.query.Query;

import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.QueryResult;
import org.nutz.dao.Sqls;
import org.nutz.dao.pager.Pager;
import org.nutz.dao.sql.Criteria;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;

import com.thinkingstar.iads.common.serviceImpl.EntityRepositoryServiceImpl;
import com.thinkingstar.iads.datacenter.entity.DcProjectDesignMajor;
import com.thinkingstar.iads.datacenter.entity.DcProjectDesignPhase;

/**
 * @ClassName: DaoDcProjectDesignPhase 
 * @Description:数据中心_项目_项目设计阶段维护
 * @author 1157372219@qq.com 
 * @date 2018年3月19日   
 */
@IocBean(args = {"refer:dao"})
public class DaoDcProjectDesignPhase extends EntityRepositoryServiceImpl<DcProjectDesignPhase>{

	public DaoDcProjectDesignPhase(Dao dao) {
		super(dao);
	}
	
	/**
	 * 逻辑删除项目设计阶段
	 * @param id
	 * @return
	 * @throws Exception 
	 */
	public int delDcProjectDesignPhaseById(String id) throws Exception{
		return delObj(id);
	}
	
	
	/**
	 * 更新项目设计阶段
	 * @param dcProjectDesignPhase
	 * @return
	 */
	public int updateDcprojectDesignPhase(DcProjectDesignPhase dcProjectDesignPhase){
		return updateObj(dcProjectDesignPhase);
	}

	/**
	 * 根据code查询全部有效的项目设计阶段
	 * @param code
	 * @return
	 */
	public List <DcProjectDesignPhase> queryDcProjectDesignPhaseByCode(String code){
		Criteria cri = Cnd.NEW();
		cri.where()
		.and("project_design_phase_code", "=", code)
		.and("del_flag", "=", false);
		List <DcProjectDesignPhase> list = query(cri);
		return list;
	}
	
	/**
	 * 根据查询条件分页查询
	 * @return
	 */
	public List <DcProjectDesignPhase> findPageListByCondition(NutMap nutMap){
		List <DcProjectDesignPhase> page_list = null;
		Criteria cri = Cnd.NEW();
		cri.where().and("del_flag", "=", false);
		cri.getOrderBy().asc("project_design_phase_code");
		if(nutMap.get("code") != null){
			cri.where().and("project_design_phase_code", "=", nutMap.get("code"));
		}
		if(nutMap.get("name") != null){
			cri.where().and("project_design_phase_name", "=", nutMap.get("name"));
		}
		cri.getOrderBy().desc("create_time");
		if(nutMap.get("page_num") != null && nutMap.get("page_size") != null){
			page_list = dao().query(DcProjectDesignPhase.class, cri, new Pager(nutMap.getInt("page_num"), nutMap.getInt("page_size")));
		}else{
			page_list = dao().query(DcProjectDesignPhase.class, cri);
		}
		return page_list;
	}
	
	/**
	 * 根据查询条件分页查询(返回分页条件)
	 * @return
	 */
	public QueryResult findDesignPhasePageListAndInfoByCondition(NutMap nutMap){
		List <DcProjectDesignPhase> page_list = null;
		Pager pager = null;
		Criteria cri = Cnd.NEW();
		cri.where().and("del_flag", "=", false);
		cri.getOrderBy().asc("project_design_phase_code");
		if(nutMap.get("code") != null){
			cri.where().and("project_design_phase_code", "=", nutMap.get("code"));
		}
		if(nutMap.get("name") != null){
			cri.where().andLike("project_design_phase_name", "%"+nutMap.get("name")+"%");
		}
		if(nutMap.get("page_num") != null && nutMap.get("page_size") != null){
			pager = new Pager(nutMap.getInt("page_num"), nutMap.getInt("page_size"));
			page_list = dao().query(DcProjectDesignPhase.class, cri, pager);
			pager.setRecordCount(dao().count(DcProjectDesignPhase.class,cri));
		}else{
			page_list = dao().query(DcProjectDesignPhase.class, cri);
		}
		return new QueryResult(page_list,pager);
	}

}
